package cloudContact.filter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

import org.apache.commons.lang.StringEscapeUtils;

public final class RequestWrapper extends HttpServletRequestWrapper {

	public RequestWrapper(HttpServletRequest servletRequest) {
		super(servletRequest);
	}

	public String[] getParameterValues(String parameter) {

	  String[] values = super.getParameterValues(parameter);
	  if (values == null) {return null;}
	  else {
	      int count = values.length;

	      String[] encodedValues = new String[count];
	      for (int i = 0; i < count; i++) {
	    	  
	    	     values[i] = values[i].replaceAll("<script", "");
	    	     values[i] = values[i].replaceAll("</script>", "");
                 encodedValues[i] = StringEscapeUtils.escapeJavaScript(values[i]);
	      }
	      	      
	      return encodedValues;
	  }
	}

	public String getParameter(String parameter) {
		  String value = super.getParameter(parameter);
		  if (value == null) {return null;}
		  else {
			  value = value.replaceAll("<script", "").replaceAll("</script>", "");
			  return StringEscapeUtils.escapeJavaScript(value);}	}
}
